<template>
	<view class="order-static">
		<view class="content" v-for="item in list" :key="item">
		<view class="title">
			{{ item.date }}
		</view>
		<uni-table ref="table" :loading="loading" border stripe  emptyText="暂无更多数据">
						<!-- <uni-tr>
							<uni-th width="150" align="center">日期</uni-th>
							<uni-th width="150" align="center">姓名</uni-th>
							<uni-th align="center">地址</uni-th>
							<uni-th width="204" align="center">设置</uni-th>
						</uni-tr> -->
						<uni-tr v-for="(v, index) in item.child" :key="index">
							<uni-td align="center">{{ v.time }}</uni-td>
							<uni-td align="center">{{v.sub.length>0?'已预约':'未预约'}}</uni-td>
							<uni-td align="center">{{ v.sub.length}}</uni-td>
							<uni-td align="center">
								<text @click="check(v)">名单 》</text>
							</uni-td>
						</uni-tr>
					<!-- 	<view class="content">
							
							<uni-tr v-for="(item, index) in 2" :key="index">
								<uni-td align="center">09:00-12:00</uni-td>
								<uni-td align="center">未预约</uni-td>
								<uni-td align="center">0</uni-td>
								<uni-td align="center">名单 》</uni-td>
							</uni-tr>
						</view> -->
						<!-- <uni-tr v-for="(item, index) in 2" :key="index">
							<uni-td align="center">09:00-12:00</uni-td>
							<uni-td align="center">未预约</uni-td>
							<uni-td align="center">0</uni-td>
							<uni-td align="center">名单 》</uni-td> -->
							<!-- <uni-td>{{ item.date }}</uni-td>
							<uni-td>
								<view class="name">{{ item.name }}</view>
							</uni-td>
							<uni-td align="center">{{ item.address }}</uni-td>
							<uni-td>
								<view class="uni-group">
									<button class="uni-button" size="mini" type="primary">修改</button>
									<button class="uni-button" size="mini" type="warn">删除</button>
								</view>
							</uni-td> -->
						<!-- </uni-tr> -->
					</uni-table>
					</view>
	</view>
</template>

<script>
// import tableData from './tableData.js'
import { GetPreorderDate } from '../../api/index.js'
export default {
	data() {
		return {
			searchVal: '',
			tableData: [],
			// 每页数据量
			pageSize: 10,
			// 当前页
			pageCurrent: 1,
			// 数据总量
			total: 0,
			loading: false,
			
			list:[]
		}
	},
	onLoad() {
		this.selectedIndexs = []
		this.getData(1)
		this.getPreorderDate()
	},
	methods: {
		async getPreorderDate(){
			let userinfo = JSON.parse(uni.getStorageSync('userinfohelper')||'')
			const { data:res } = await GetPreorderDate({hid:userinfo.id,date:'2024-05-30'})
			console.log(res,'d')
			console.log(res,'date')
			// let ress = res.data.filter(item=>item.date==this.currentDate)
			const group = res.data.reduce((group,item)=>{
				if(!group[item.date]){
					group[item.date]=[]
				}
				group[item.date].push(item)
				return group
			},{})
			
			console.log(group,'group')
			// this.list=[...group]
			for(let item in group){
				console.log(group[item],'group[item]')
				const g = group[item].reduce((g,v)=>{
					if(!g[v.time]){
						g[v.time]=[]
					}
					g[v.time].push(v)
					return g
				},{})
				console.log(g,'g')
				let child =[]
				for(let k in g){
					child.push({time:k,sub:g[k]})
					console.log(k,'k')
					// this.list.push({date:item,cc:{time:k,c:g[k]}})
				}
				// console.log(child,'cc')
				
				// this.list.push({time:item,info:group[item]})
				this.list.push({date:item,child})
			}
			let a=''
			let b=''
			// for(let v in group){
			// 	console.log(v,group[v])
			// 	this.info.selected.push({date:v,info:group[v].length>=2?'已满':'预约'})
					
			// 	console.log(this.info.selected,'this.info.selected')
			// }
		},
		check(v){
			console.log('55',v)
			uni.navigateTo({
				url:'/subPackageHH/OrderTable/OrderTable?info='+JSON.stringify(v)
			})
		},
		// 多选处理
		selectedItems() {
			// return this.selectedIndexs.map(i => this.tableData[i])
		},
		// 多选
		selectionChange(e) {
			console.log(e.detail.index)
			// this.selectedIndexs = e.detail.index
		},
		//批量删除
		delTable() {
			// console.log(this.selectedItems())
		},
		// 分页触发
		change(e) {
			// this.$refs.table.clearSelection()
			// this.selectedIndexs.length = 0
			// this.getData(e.current)
		},
		// 搜索
		search() {
			// this.getData(1, this.searchVal)
		},
		// 获取数据
		getData(pageCurrent, value = '') {
			// this.loading = true
			// this.pageCurrent = pageCurrent
			// this.request({
			// 	pageSize: this.pageSize,
			// 	pageCurrent: pageCurrent,
			// 	value: value,
			// 	success: res => {
			// 		// console.log('data', res);
			// 		this.tableData = res.data
			// 		this.total = res.total
			// 		this.loading = false
			// 	}
			// })
		},
		// 伪request请求
		request(options) {
			// const { pageSize, pageCurrent, success, value } = options
			// let total = tableData.length
			// let data = tableData.filter((item, index) => {
			// 	const idx = index - (pageCurrent - 1) * pageSize
			// 	return idx < pageSize && idx >= 0
			// })
			// if (value) {
			// 	data = []
			// 	tableData.forEach(item => {
			// 		if (item.name.indexOf(value) !== -1) {
			// 			data.push(item)
			// 		}
			// 	})
			// 	total = data.length
			// }

			// setTimeout(() => {
			// 	// typeof success === 'function' &&
			// 	// 	success({
			// 	// 		data: data,
			// 	// 		total: total
			// 	// 	})
			// }, 500)
		}
	}
}
</script>

<style lang="scss">
	.uni-table-tr{
		width: 100%;
	}
.order-static{
	width: 100%;
	.content{
		text-align: center;
		.title{
			text-align: center;
		}
		.uni-table{
			width: 100%;
			// border: 1px solid #000;
			
		}
	}
}
</style>
